package com.wasion.pwportable.protocol.p2;


/**
 * 
 * @ClassName: Iec101Parser
 * @Description: IEC 101规约解析
 * @author 高意
 * @date Apr 26, 2016 3:00:21 PM
 * 
 */
public class Iec101Parser {

	// 控制域长度
	protected FrameFieldsLength.ControlFieldLengthEnum CONTROL_FIELD_LENGTH = FrameFieldsLength.ControlFieldLengthEnum.LENGTH_CONTROL_FIELD_1;

	// 链路地址长度
	protected FrameFieldsLength.LinkAddrLengthEnum LINK_ADDR_LENGTH = FrameFieldsLength.LinkAddrLengthEnum.LENGTH_LINK_ADDR_2;

	// ASDU地址长度
	protected FrameFieldsLength.AsduPublicAddrLengthEnum ASDU_ADDR_LENGTH = FrameFieldsLength.AsduPublicAddrLengthEnum.LENGTH_ASDU_ADDR_2;

	// 传输原因长度
	protected FrameFieldsLength.COTLengthEnum COT_LENGTH = FrameFieldsLength.COTLengthEnum.LENGTH_COT_1;

	// 信息对象地址长度
	protected FrameFieldsLength.InfoObjectAddrLengthEnum INFO_OBJ_ADDR_LENGTH = FrameFieldsLength.InfoObjectAddrLengthEnum.LENGTH_INFO_ADDR_2;

	// 固定帧对象
	protected FixedFrame fixedFrame;

	// 可变帧对象
	protected VariableFrame variableFrame;

	public FixedFrame getFixedFrame() {
		return fixedFrame;
	}

	public VariableFrame getVariableFrame() {
		return variableFrame;
	}

	/**
	 * 构造方法
	 */
	public Iec101Parser() {
	}

	/**
	 * 数据解析
	 * 
	 * @description 标准101报文数据解析
	 * @param data
	 * @param equip_addr
	 */
	public Iec101Parser(byte[] data) {

		try {
			if (10 == data[0]) {// 固定帧长帧
				fixedFrame = new FixedFrame(data, LINK_ADDR_LENGTH);
			} else { // 可变帧长帧
				variableFrame = new VariableFrame(data,
						ProtocolEnum.TypeEnum.IEC_101, CONTROL_FIELD_LENGTH,
						LINK_ADDR_LENGTH, ASDU_ADDR_LENGTH, COT_LENGTH,
						INFO_OBJ_ADDR_LENGTH);
			}
		} catch (Exception e) {
			System.err.println("IEC 101报文解析发生异常! >>>> ");
			e.printStackTrace();
		}
	}
}
